<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\StoreBargain;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class StoreBargainController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new StoreBargain(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('image')->image('',100,100);
            $grid->column('bargain_name','砍价名称');
            $grid->column('price');
            $grid->column('min','最低价');
            $grid->column('join','参与人数');
            $grid->column('help','帮忙砍价人数');
            $grid->column('success','砍价成功人数');
            $grid->column('limit','限量');
            $grid->column('limit_have','限量剩余');
            $grid->column('end_time','结束时间');
            $grid->column('status')->switch('', true);
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new StoreBargain(), function (Show $show) {
            $show->field('id');
            $show->field('image');
            $show->field('bargain_name');
            $show->field('price');
            $show->field('min');
            $show->field('join');
            $show->field('help');
            $show->field('success');
            $show->field('limit');
            $show->field('limit_have');
            $show->field('end_time');
            $show->field('status');
            $show->field('created_at');

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new StoreBargain(), function (Form $form) {
            $form->display('id');
            $form->text('image');
            $form->text('bargain_name');
            $form->text('price');
            $form->text('min');
            $form->text('join');
            $form->text('help');
            $form->text('success');
            $form->text('limit');
            $form->text('limit_have');
            $form->text('end_time');
            $form->text('status');

            $form->display('created_at');

        });
    }
}
